import QtQuick 2.0
import QtQuick.Controls 1.1
import "../FKWidget/"

FKWidget{
    id:roomWidget
    relativeHeight: 1
    relativeWidth: 1
    relativeInitialX: 0
    relativeInitialY: 0
    hideAnimation: true
    showAnimation: false

    signal start
    signal quit
    signal changeActorsProperty(var row, var col, var val)

    function setColumnOptionsModel(column, columnModel){
        switch(column){
        case 0:
            columnOption0=columnModel;
            break;
        case 1:
            columnOption1=columnModel;
            break;
        case 2:
            columnOption2=columnModel;
            break;
        case 3:
            columnOption3=columnModel;
            break;
        case 4:
            columnOption4=columnModel;
            break;
        case 5:
            columnOption5=columnModel;
            break;
        case 6:
            columnOption6=columnModel;
            break;
        case 7:
            columnOption7=columnModel;
            break;
        case 8:
            columnOption8=columnModel;
            break;
        case 9:
            columnOption9=columnModel;
            break;
        }
    }

    function startLoading(val1, val2){
        hpb.maximumValue=val1
        vpb.maximumValue=val2
        viewport.state="loading"
    }
    function setLoadingProgress(val1,val2){
        hpb.value=val1
        vpb.value=val2
    }
    function addLoadingProgress(val1,val2){
        hpb.value+=val1
        vpb.value+=val2
    }

    property var columnOption0
    property var columnOption1
    property var columnOption2
    property var columnOption3
    property var columnOption4
    property var columnOption5
    property var columnOption6
    property var columnOption7
    property var columnOption8
    property var columnOption9

    property var rowDelegate: rowDelegateComponent

    FKViewport{
        id:viewport
        state:""
        ProgressBar{
            id:hpb
            anchors{
                left:parent.left
                bottom: parent.bottom
                right:parent.right
                leftMargin: 10
                rightMargin: 10
                bottomMargin: 10
            }
            height:0
            minimumValue: 0
        }
        ProgressBar{
            id:vpb
            orientation: Qt.Vertical
            anchors{
                top: parent.top
                right:parent.right
                bottom:hpb.top
                topMargin: 10
                rightMargin: 10
                bottomMargin: 0
            }
            width:0
            minimumValue: 0
        }
        Rectangle{
            anchors{
                left:parent.left
                top:parent.top
                bottom: hpb.top
                right:rightArea.left
                margins:10
            }
            ListView{
                anchors.fill: parent
                model:(typeof (actorsModel) !== "undefined" ? actorsModel : null)
                delegate:rowDelegate
                spacing: 10
            }
        }
        Item{
            id:rightArea
            width:parent.width*0.25
            anchors{
                right:vpb.left
                top:parent.top
                bottom: hpb.top
                margins: 10
            }
            Column{
                anchors{
                    right:parent.right
                    left:parent.left
                    bottom: parent.bottom
                }
                Button{
                    anchors{
                        right:parent.right
                        left:parent.left
                    }
                    text:qsTr("Start")
                    onClicked: roomWidget.start()
                }
                Button{
                    anchors{
                        right:parent.right
                        left:parent.left
                    }
                    text:qsTr("Quit room")
                    onClicked: roomWidget.quit()
                }
            }
        }
        states: [
            State {
                name: ""
                PropertyChanges {
                    target: hpb
                    height:0
                }
                PropertyChanges {
                    target: vpb
                    width:0
                }
                PropertyChanges {
                    target: viewport
                    enabled: true
                }
            },
            State {
                name: "loading"
                PropertyChanges {
                    target: hpb
                    height: 20
                }
                PropertyChanges {
                    target: vpb
                    width: 20
                }
                PropertyChanges {
                    target: viewport
                    enabled: false
                }
            }
        ]
        transitions: [
            Transition {
                from: "*"
                to: "*"
                NumberAnimation { target: hpb; property: "height"; duration: 200; easing.type: Easing.InOutQuad }
                NumberAnimation { target: vpb; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
            }
        ]
    }

    Component{
        id:rowDelegateComponent
        Row{
            height: col1.height
            spacing: 10
            Text{
                id:col1
                text: (typeof (nameRole) !== "undefined" ? nameRole : "")
                font.pointSize: 14
                font.italic: true
                width: 180
            }
//            ComboBox{
//                id:col2
//                model:columnOption1;
//                height: col1.height
//            }
        }
    }
}
